package com.android.launcher3;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ProgressBar;

public class MenuDrawer extends FrameLayout implements DropTarget {
	private MenuManager mMenuManager;
	private ProgressBar mProgressBar;
	private static final String TAG = "MenuDrawer";

	/**
	 * Creates a new MenuDrawer object.
	 */
	public MenuDrawer(final Context context) {
		this(context, null);
	}

	/**
	 * Creates a new MenuDrawer object.
	 */
	public MenuDrawer(final Context context, final AttributeSet attrs) {
		this(context, attrs, 0);
	}

	/**
	 * Creates a new MenuDrawer object.
	 */
	public MenuDrawer(final Context context, final AttributeSet attrs,
			final int defStyle) {
		super(context, attrs, defStyle);
	}

	public boolean acceptDrop(DragSource source, int x, int y, int xOffset,
			int yOffset, Object dragInfo) {
		LogUtils.d(TAG, "acceptDrop");

		return true;
	}

	public void onDragEnter(DragSource source, int x, int y, int xOffset,
			int yOffset, Object dragInfo) {
		LogUtils.d(TAG, "onDragEnter");
		this.mMenuManager.onDragEnter(source, x, y, xOffset, yOffset, dragInfo);
	}

	public void onDragExit(DragSource source, int x, int y, int xOffset,
			int yOffset, Object dragInfo) {
		LogUtils.d(TAG, "onDragExit");
		this.mMenuManager.onDragExit(source, x, y, xOffset, yOffset, dragInfo);
	}

	public void onDragOver(DragSource source, int x, int y, int xOffset,
			int yOffset, Object dragInfo) {
		LogUtils.d(TAG, "onDragOver");
		this.mMenuManager.onDragOver(source, x, y, xOffset, yOffset, dragInfo);
	}

	public void onDrop(final DragSource paramDragSource, final int paramInt1,
			final int paramInt2, final int paramInt3, final int paramInt4,
			final Object paramObject) {
		LogUtils.d(TAG, "onDrop");

		DragSource localDragSource = paramDragSource;
		int i = paramInt1;
		int j = paramInt2;
		int k = paramInt3;
		int m = paramInt4;
		Object localObject = paramObject;
		this.mMenuManager.onDrop(localDragSource, i, j, k, m, localObject);
	}

	public void setBackgroundClose() {
		LogUtils.d(TAG, "setBackgroundClose");

		// Context localContext = getContext();
		//
		// if (LauncherConfig.getUse16BitWindow(localContext)) {
		// if (((WallpaperManager) localContext.getSystemService("wallpaper"))
		// .getWallpaperInfo() == null) {
		// } else {
		// setBackgroundResource(R.color.menu_screen_background);
		// }
		// }
	}

	public void setBackgroundImage() {
		LogUtils.d(TAG, "setBackgroundImage");

		// Context localContext = getContext();

		// if (LauncherConfig.getUse16BitWindow(localContext)) {
		// if (((WallpaperManager) localContext.getSystemService("wallpaper"))
		// .getWallpaperInfo() != null) {
		// setBackgroundResource(R.color.menu_screen_background);
		//
		// return;
		// }
		// }

		// setBackgroundResource(R.color.menu_background);
		this.setBackgroundColor(Color.parseColor("#00000000"));
	}

	public void setEnabledProgress(final boolean enabledProgress) {
		// Log.e(TAG, "setEnabledProgress=" + enabledProgress);
		LogUtils.d(TAG, "setEnabledProgress=" + enabledProgress);
		if (enabledProgress) {
			this.mProgressBar.setVisibility(View.VISIBLE);
		} else {
			this.mProgressBar.setVisibility(View.GONE);
		}
	}

	protected void onFinishInflate() {
		LogUtils.d(TAG, "onFinishInflate");
		super.onFinishInflate();

		this.mProgressBar = (ProgressBar) getChildAt(0);
		this.mProgressBar.setIndeterminate(true);

		this.mMenuManager = (MenuManager) getChildAt(1);
		setAnimationCacheEnabled(false);
	}
}
